<template>
  <div>
    <Form ref="form" :model="formData" :rules="formDataRules" :label-width="140">
      <Card title="修改验收事项" dis-hover class="ivu-mt">
        <Row>
          <Col span="18" offset="2">
          <FormItem label="验收事项名称" prop="itemName">
            <Input v-model.trim="formData.itemName" placeholder="请输入资质名称" maxlength="100"></Input>
          </FormItem>
          </Col>
          <Col span="18" offset="2">
          <FormItem label="检验类型" prop="itemType">
            <Select v-model="formData.itemType" filterable>
              <Option v-for="item in brandList" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="18" offset="2">
          <FormItem label="">
            <Button type="primary" :loading="rLoading" @click="toRelease('form')">提交</Button>
            <Button @click="goBack" class="ivu-ml">取消</Button>
          </FormItem>
          </Col>
        </Row>
      </Card>
    </Form>
  </div>
</template>
<script>
  import { ApiRequest } from '@api/basePage'
  export default {
    data() {
      return {
        rLoading: false,
        pickerOptions: {
          disabledDate(date) {
            return date && date.valueOf() < Date.now() - 86400000;
          },
        },
        brandList: [{
          value: '1',
          label: '数值'
        },
        {
          value: '2',
          label: '文本'
        }],
        showAreaNames: '',
        salableAreaData: [],
        areaNames: [],
        cityUuids: [],
        productDetailImages: [], //图片回显
        formData: {
          itemName: '',
          itemType: '', //验收事项类型1数字2文本
          uuid: ''
        },
        requestParams: {
          uuid: ''
        },
        formDataRules: {
          itemName: [
            { required: true, message: '请输入验收事项名称', trigger: 'blur' },
            // { type: 'string', min: 2, max: 100, message: '文字最多输入100个字符，最少输入2个字符（汉字、英文字母、标点、数字均算一个字符）', trigger: 'blur' }
          ],
        },
        requestApi: { // 视情况自定义
          // 新增品牌
          baseGetByUuid: {
            url: '/sysback/acceptitem/acceptitem/baseGetByUuid', // 接口地址
            type: 'post' // 接口请求类型
          },
          baseUpdate: {
            url: '/sysback/acceptitem/acceptitem/baseUpdate', // 接口地址
            type: 'post' // 接口请求类型
          },
        },
      }
    },
    mounted() {
      this.baseGetByUuid();
    },
    methods: {
      baseGetByUuid() {
        let requestParams = {
          uuid: this.$route.query.uuid
        };
        ApiRequest(this.requestApi.baseGetByUuid.url, this.requestApi.baseGetByUuid.type, requestParams, true).then(res => {
          if (res.retStatus === '1') {
            if (res.retData !== '') {
              let rData = res.retData;
              this.formData = {
                itemName: rData.itemName,
                itemType: rData.itemType,
                uuid: rData.uuid,
                enable: rData.enable || 1
              }
            }
          }
        })
      },
      //保存按钮
      toRelease(name) {
        this.$refs[name].validate(valid=>{
           if(valid){
             this.rLoading = true;
             ApiRequest(this.requestApi.baseUpdate.url, this.requestApi.baseUpdate.type,
               this.formData, false).then(res => {
               if (res.retStatus === '1') {
                 this.$Message.success('修改成功!');
                 this.$router.go(-1);
               }
               this.rLoading = false;
             })
           }
        })
      },
      goBack() {
        this.$router.go(-1);
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
